<template>
	<view class="container">
		<!-- <view class="titletop">
			<image src="../../static/dbgoback.png" mode="widthFix" style="width: 20px;height: 20px;margin-left: 20px;" @click="goback"></image>
			<text style="font-size: 16px; font-weight: 700;margin-left: 30%;">护群设置</text>
		</view> -->
		<view class="zjl_header">
			<button plain="true" @click="heimingdan">黑名单管理</button>
			<button plain="true" @click="qiangbaoshou">抢包手管理</button>
		</view>

		<view class="uni-list">
			<view>非抢包手枪包</view>
			<radio-group @change="checkboxChange" >
				<label class="uni-list-cell uni-list-cell-pd"  v-for="item in fitems">
					<view>
						<radio :value="item.value" :checked="Safeguard.fqbsqb.includes(item.value)" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</radio-group>
		</view>

		<view class="uni-list">
			<view>黑名单乘员入群</view>
			<radio-group @change="checkboxChange2">
				<label class="uni-list-cell uni-list-cell-pd"   v-for="item in hitems">
					<view>
						<radio :value="item.value" :checked="Safeguard.hmbcyrq.includes(item.value)" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</radio-group>
		</view>

		<view class="uni-list">
			<view>邀请进群管理</view>
			<radio-group @change="checkboxChange3"  >
				<label class="uni-list-cell uni-list-cell-pd" v-for="item in qitems">
					<view>
						<radio :value="item.value" :checked="Safeguard.jqgl.includes(item.value)" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</radio-group>
		</view>
		
		<view style="width: 200px;height: 40px;text-align: center;display: flex;justify-content: center;align-items: center;background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);border-radius: 40px;color: #FFFFFF;margin-left: 50%;transform: translateX(-50%);margin-top: 10px;"    @click="qkshezhi">
			清空所有设置
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				roomid:'',
				jqgl:'',
				hmbcyrq:'',
				fqbsqb:'',
				Safeguard:[],
				fitems: [{
						name: '自动群内警告',
						checked: false,
						value:1
					},
					{
						name: '抢包5次自动踢',
						checked: false,
						value:2
					}
				],
				hitems: [{
						name: '自动踢',
						checked: false,
						value:1
					},
					{
						name: '群内警告',
						checked: false,
							value:2
						
					}
				],
				qitems: [{
						name: '玩家6分钟无发包，提醒发包',
						checked: false,
						value:1
					},
					{
						name: '玩家8分钟无发包，自动踢',
						checked: false,
							value:2
					}
				]
			}
		},
		onLoad(options) {
			console.log(options)
			this.roomid=options.roomid
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/lz/getSafeguard',
				method: "POST",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				data:{
					qid:this.roomid
				},
				success: (res) => {
					console.log(res.data.data)
					this.Safeguard = res.data.data
				},
				fail: (err) => {
					console.log(err)
				}
			});
		},
		methods: {
			checkboxChange(e) {
				console.log(e)
				console.log(e.detail.value+"")

				this.fqbsqb=e.detail.value+""
								console.log('进群管理')
				console.log(this.jqgl)
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/setSafeguard',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.roomid,
						jqgl:this.jqgl,
						fqbsqb:this.fqbsqb,
						hmbcyrq:this.hmbcyrq
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:'操作成功'
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			checkboxChange2(e) {
				console.log(e)
				console.log(e.detail.value+'')
				this.hmbcyrq = e.detail.value+''
				console.log('非抢包手抢包')
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/setSafeguard',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.roomid,
						jqgl:this.jqgl,
						fqbsqb:this.fqbsqb,
						hmbcyrq:this.hmbcyrq
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:'操作成功'
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			checkboxChange3(e) {
				console.log(e)
				console.log(e.detail.value+'')
				this.jqgl = e.detail.value+''
				console.log('进群管理')
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/setSafeguard',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.roomid,
						jqgl:this.jqgl,
						fqbsqb:this.fqbsqb,
						hmbcyrq:this.hmbcyrq
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:'操作成功'
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			goback() {
				uni.navigateBack({
					delta: 1
				})
			},
			qkshezhi(){
				
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/delSafeguard',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.roomid,
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:'操作成功'
							})
						}
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			qiangbaoshou() {
				uni.navigateTo({
					url: "./qbs?qid="+this.roomid
				})
			},
			heimingdan() {
				uni.navigateTo({
					url: "../heimingdan/heimingdan?roomid="+this.roomid
				})
			}
		}
	}
</script>

<style scoped>
	.container {
		padding-top: 30px;
	}

	.titletop {
		display: flex;
		align-items: center;

	}

	.zjl_header {
		display: flex;
		justify-content: space-between;
		margin-top: 15px;

	}

	.zjl_header button {
		font-size: 14px;
		border: 0;
	}

	.uni-list {
		margin-left: 20px;
		margin-top: 15px;
		font-size: 17px;
	}

	.uni-list-cell {
		display: flex;
		justify-content: flex-start;
		padding: 10px;
	}
</style>
